/**
 * @param {Number} 时间数如 120
 * @return {String} 00:02:00
 */
export function formatSeconds(value) {
    let theTime = parseInt(value);// 需要转换的时间秒
    let theTime1 = 0;// 分
    let theTime2 = 0;// 小时
    if(theTime > 60) {
        theTime1 = parseInt(theTime/60);
        theTime = parseInt(theTime%60);
        if(theTime1 > 60) {
            theTime2 = parseInt(theTime1/60);
            theTime1 = parseInt(theTime1%60);
            if(theTime2 > 24){
            //大于24小时
                theTime2 = parseInt(theTime2%24);
            }
        }
    }
    return `${(theTime2 > 10 ? theTime2 : '0' + theTime2)}:${(theTime1 > 10 ? theTime1 : '0' + theTime1)}:${(theTime > 10 ? theTime : '0' + theTime)}`;
}

/**
 * @param {Number} 时间戳
 * @param {format} 时间格式
 * @return {String} 2020.6.29 9:38
 */

export function formatTime(number,format) {

  var formateArr  = ['Y','M','D','h','m','s'];
  var returnArr   = [];

  var date = new Date(number * 1000);
  returnArr.push(date.getFullYear());
  returnArr.push(formatNumber(date.getMonth() + 1));
  returnArr.push(formatNumber(date.getDate()));

  returnArr.push(formatNumber(date.getHours()));
  returnArr.push(formatNumber(date.getMinutes()));
  returnArr.push(formatNumber(date.getSeconds()));

  for (var i in returnArr)
  {
    format = format.replace(formateArr[i], returnArr[i]);
  }
  return format;
}

//数据转化
function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//将秒转化为时分秒
export function formateSeconds(endTime){
    let secondTime = parseInt(endTime)//将传入的秒的值转化为Number
    let min = 0// 初始化分
    let h =0// 初始化小时
    let result=''
    if(secondTime>60){//如果秒数大于60，将秒数转换成整数
      min=parseInt(secondTime/60)//获取分钟，除以60取整数，得到整数分钟
      secondTime=parseInt(secondTime%60)//获取秒数，秒数取佘，得到整数秒数
      if(min>60){//如果分钟大于60，将分钟转换成小时
        h=parseInt(min/60)//获取小时，获取分钟除以60，得到整数小时
        min=parseInt(min%60) //获取小时后取佘的分，获取分钟除以60取佘的分
      }
    }
    result=`${h.toString().padStart(2,'0')}时${min.toString().padStart(2,'0')}分`
    return result
  }

// time格式为 '2018-08-01或2018/08/01或2018/8/1'
export function daysComputed(time){
  let oldTimeFormat = new Date(time)
  let nowDate = new Date()

  let times =oldTimeFormat.getTime()- nowDate.getTime()
  let days = parseInt(times / (60*60*24*1000))
  return days
}

/**
 * 参数 diffValue  时间戳
 *
 */

export function getDate(diffValue){
    var minute = 60;
    var hour = minute * 60;
    var day = hour * 24;
    var month = day * 30;

    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    var res = '';
    var nowTime = (new Date()).getTime(); // 获取当前时间戳
    if(monthC>=12){
        var oldTime = nowTime - diffValue      // 获取记录的时间戳
        var date = new Date(oldTime);
        res = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();

    }else if(monthC>=1){
        res = parseInt(monthC) + "个月前";
    }
    else if(weekC>=1){
        res = parseInt(weekC) + "周前"
    }
    else if(dayC>=1){
        res = parseInt(dayC)
    }
    return res;
}

/**
 * 参数 def  时间戳 倒计时
 *
 */
export function getDay(def) {
    if(!def){
        return
    }
    var updata_time = Math.round(new Date().getTime() / 1000).toString();
    if(def > updata_time){
        var num_day = parseInt((def - updata_time) / (60 * 60 * 24)) + 1;
    }
    if(def <= updata_time){
        var num_day = parseInt((updata_time - def) / (60 * 60 * 24)) + 1;
    }
    return num_day
}

/**
 * 参数 def  时间戳 2时 80分
 *
 */
export function getHour(def) {
    var res="";
    var hour = parseInt((def) / ( 60 * 60));
    var minute = parseInt((hour%60));
    return hour
}
export function getMinute(def) {
    var res="";
    var hour = parseInt((def) / ( 60));
    var minute = parseInt((hour%60));
    return minute
}

/**
 * 图片宽度和高度转换
 *
 */
export function getImgH(W,H) {
    let h;
    h = parseInt(690*H/W)
    return h
}
export function getImgH2(W,H) {
    let h;
    h = parseInt(750*H/W)
    return h
}
/**
 * 图片宽度和高度转换
 *
 */
export function getCoordinates(WH) {
    let Wh;
    Wh = parseInt(690*WH/800)
    return Wh
}
